package org.maverickjs.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;
import org.maverickjs.application.MessageRepository;
import org.maverickjs.model.bean.UserJB;


@WebServlet("/refreshPage.do")
public class RefreshPageServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
    
	private int aux = 0;
	
    public RefreshPageServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			
			JSONObject jsonObject = new JSONObject();
			UserJB user = (UserJB) request.getSession().getAttribute("user");			

			jsonObject.put("message", MessageRepository.getInstance().getMessage());			
			jsonObject.put("userId", user.getId());
			jsonObject.put("userName", user.getUserName());
			
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			out.print(jsonObject);
			out.flush();
			out.close();
			
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
